﻿using MyCompany.MyProject.Model.Models;
using MyCompany.MyProject.Repository.Base;
using MyCompany.MyProject.Repository.UnitOfWork;
using Newtonsoft.Json;
using SqlSugar;

namespace MyCompany.MyProject.Repository
{
    public class UserRepository : BaseRepository<SysUserInfo>, IUserRepository
    {
        public UserRepository(IUnitOfWorkManage unitOfWork) : base(unitOfWork)
        {
        }

        public async Task<List<SysUserInfo>> Query()
        {
            await Task.CompletedTask;
            var data = "[{\"Id\": 18,\"Name\":\"laozhang\"},{\"Id\": 16,\"Name\":\"老王\"}]";
            return JsonConvert.DeserializeObject<List<SysUserInfo>>(data) ?? new List<SysUserInfo>();
        }

        public async Task<List<RoleModulePermission>> RoleModuleMaps()
        {
            return await QueryMuch<RoleModulePermission, Modules, Role, RoleModulePermission>(
                (rmp, m, r) => new object[]
                {
                    JoinType.Left,rmp.ModuleId==m.Id,
                    JoinType.Left,rmp.RoleId == r.Id
                },
  (rmp, m, r) => new RoleModulePermission()
  {
      Role = r,
      Modules = m,
      IsDeleted = rmp.IsDeleted,
  },
  (rmp, m, r) => rmp.IsDeleted == false && m.IsDeleted == false && r.IsDeleted == false
                );
        }
    }
}
